package com.ruoyi.system.outto.goods.impl;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.V2.inter.mapper.SelectPushMapper;
import com.ruoyi.system.model.domain.GameAttribute;
import com.ruoyi.system.model.domain.GoodsInfoImg;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.dto.PangXieAttrUtil;
import com.ruoyi.system.outto.game.CommonApi;
import com.ruoyi.system.outto.goods.QIANPangXieApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/20 14:07
 */
@Slf4j
@Service
@Order(4)
public class QIANPangXieApiImpl implements QIANPangXieApi {

    @Resource
    private CommonApi commonApi;

    @Resource
    private ArtRecMapper artRecMapper;

    @Resource
    private RedisCache redisCache;

    @Resource
    private SelectPushMapper selectPushMapper;


    @Resource
    private GameAttributeMapper gameAttributeMapper;

    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;

    private static Integer game_id;

    public static void initialization(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto) {
        if (goodsInfoAndAttrValueDto.getGameName().contains("王者荣耀")) {
            game_id = 13;
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("和平精英")) {
            game_id = 11;
        } else if (goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟")) {
            game_id = 12;
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("原神")) {
            game_id = 26;
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("穿越火线")) {
            game_id = 39;
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("枪战王者")) {
            game_id = 33;
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("蛋仔派对")) {
            game_id = 142;
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("火影忍者")) {
            game_id = 32;
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("地下城与勇士")) {
            game_id = 25;
        } else if (goodsInfoAndAttrValueDto.getGameName().equals("永劫无间")) {
            game_id = 23;
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("无畏契约")) {
            game_id = 148;
        } else if (goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟(手游)")) {
            game_id = 36;
        } else if (goodsInfoAndAttrValueDto.getGameName().equals("永劫无间手游")) {
            game_id = 409;
        } else if (goodsInfoAndAttrValueDto.getGameName().equals("金铲铲之战")) {
            game_id = 31;
        } else if (goodsInfoAndAttrValueDto.getGameName().equals("暗区突围")) {
            game_id = 110;
        }
    }

    public void main(String[] args) {
        SalePartner salePartner = new SalePartner();
        salePartner.setSaleKey("17344124999");
        salePartner.setOther("aa120120");
        salePartner.setTwoOther("fe131d7f5a6b38b23cc967316c13dae2");
        salePartner.setThreeOther("7f1d0ff37b6922acdfa4b309f1c25eff");
        String attrs = getAttrs(36,salePartner);
        log.info(attrs);
//        Map<String,Object> params = new HashMap<>();
//        Map<String,Object> hrader = new HashMap<>();
//        params.put("game_id",26);
//        params.put("acc_source",0);
//        params.put("bind_psn",1);
//        params.put("bind_tap",1);
//        params.put("category","{\\\"1\\\":250,\\\"5\\\":134,\\\"6\\\":229,\\\"8\\\":252,\\\"27\\\":0,\\\"28\\\":714}");
//        params.put("description","【78黄，满命神里绫华】 冒险等级: 60 6命金色角色: 满命神里绫华 4命金色角色: 四命迪卢克,四命七七 3命金色角色: 三命莫娜,三命珊瑚宫心海 2命金色角色: 二命宵宫,二命琴,二命荒泷一斗,二命纳西妲 1命金色角色: 一命优菈,");
//        params.put("game_account","pangkangxiong07905@163.com");
//        params.put("game_pwd","pangkangxiong07905@163.com");
//        params.put("price","1000");
//        String token = getToken(salePartner);
////        hrader.put("Authorization",token);
////        hrader.put("Accept","application/json, text/plain, */*");
//        String response = HttpRequest.post("https://api.pxb7.com/api/product/add")
//                .header("Authorization",token)
//                .header("Origin","https://www.pxb7.com")
//                .header("Loginstatus","true")
//                .body(JSONObject.toJSONString(params)).execute().body();
////        String response = HttpUtil.doPost1("https://api.pxb7.com/api/product/add",params,hrader);
//        log.info("螃蟹添加接口返回参数={}", response);
    }

//    public void sleep(){
//        Random random = new Random();
//
//        // 设置最小和最大休眠时间（单位为毫秒）
//        int minTime = 10000; // 最小休眠时间为10秒
//        int maxTime = 15000; // 最大休眠时间为15秒
//
//        // 计算随机休眠时间并转换为long型
//        long sleepTime = (random.nextInt((maxTime - minTime) + 1)) + minTime;
//        try {
//            Thread.sleep(sleepTime);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//    }

    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
//        sleep();
        initialization(goodsInfoAndAttrValueDto);
        Map<String, Object> params = params(goodsInfoAndAttrValueDto,salePartner);
        String token = getToken(salePartner);
        String response = send(token, "https://api.pxb7.com/api/product/add", params);
        log.info("螃蟹添加接口请求参数={}", JSONObject.toJSONString(params));
        log.info("螃蟹添加接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);

        Map<String, Object> result = new HashMap<>();
        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            String data = resultJson.getString("data");
            String id = JSONObject.parseObject(data).getString("id");
            result.put("outId", id);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson);
        return AjaxResult.success(result);

    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto,
                               SalePartner salePartner) {
        initialization(goodsInfoAndAttrValueDto);
        Map<String, Object> params = new HashMap<>();
        params.put("game_id",game_id);
        params.put("id",goodsInfoAndAttrValueDto.getOutId());
        params.put("price",goodsInfoAndAttrValueDto.getPrice().setScale(0, BigDecimal.ROUND_FLOOR).toPlainString());
        String token = getToken(salePartner);
//        String response = HttpRequest.post("https://api.pxb7.com/api/product/price")
//                .header("Authorization",token)
//                .header("Origin","https://www.pxb7.com")
//                .header("Loginstatus","true")
//                .body(JSONObject.toJSONString(params)).execute().body();
        String response = send(token, "https://api.pxb7.com/api/product/price", params);
        log.info("螃蟹改价接口请求参数={}", JSONObject.toJSONString(params));
        log.info("螃蟹改价接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);

        Map<String, Object> result = new HashMap<>();
        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson);
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner
            salePartner) {
        initialization(goodsInfoAndAttrValueDto);
        Map<String, Object> params = new HashMap<>();
        params.put("game_id",game_id);
        if(StringUtils.isEmpty(goodsInfoAndAttrValueDto.getOutId())){
            throw new GlobalException("当前账号未上架!!!");
        }
        params.put("id",goodsInfoAndAttrValueDto.getOutId());
        String token = getToken(salePartner);
        String response = send(token, "https://api.pxb7.com/api/product/offshelf", params);
        log.info("螃蟹下架接口请求参数={}", JSONObject.toJSONString(params));
        log.info("螃蟹下架接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);

        Map<String, Object> result = new HashMap<>();
        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson);
        return AjaxResult.success(result);
    }
    String send(String token, String url, Map<String, Object> params) {

        Map<String, Object> filteredParams = params.entrySet().stream()
                .filter(entry -> !entry.getValue().toString().isEmpty())
                .collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue(), (a, b) -> a));
        TreeMap<String, Object> treeMap = new TreeMap<>(filteredParams);

        long timestamp = System.currentTimeMillis() / 1000;
        String appSecret = "198f788b9ee343209e0121bf72e8c562";
        String ranString = getRanString();
        StringBuilder sb = new StringBuilder();
        sb.append("APPSECRET=");
        sb.append(appSecret);
        sb.append("&");
        sb.append(JSONObject.toJSONString(treeMap));
        sb.append("&TIMESTAMP=");
        sb.append(timestamp);
        sb.append("&RANDOMSTR=");
        sb.append(ranString);
//        System.out.println(sb.toString().toUpperCase());
        String sign = DigestUtils.md5Hex(sb.toString().toUpperCase());
//        System.out.println(sign);
        return HttpRequest.post(url)
                .header("Accept", "application/json, text/plain, */*")
                .header("Accept-Language", "zh-CN,zh;q=0.9")
                .header("Authorization", token)
                .header("Connection", "keep-alive")
                .header("Content-Type", "application/json;charset=UTF-8")
                .header("Loginstatus", "true")
                .header("Origin", "https://www.pxb7.com")
                .header("Sec-Fetch-Dest", "empty")
                .header("Sec-Fetch-Mode", "cors")
                .header("Sec-Fetch-Site", "same-site")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like " +
                        "Gecko) Chrome / 122.0 .0 .0 Safari / 537.36 ")
                .header("randomStr", ranString)
                .header("sec-ch-ua", "\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";" +
                        "v=\"122\"")
                .header("sec-ch-ua-mobile", "?0")
                .header("sec-ch-ua-platform", "\"Windows\"")
                .header("sign", sign)
                .header("timestamp", String.valueOf(timestamp))
                .body(JSONObject.toJSONString(params)).execute().body();
    }
    public static String removeNonDigits(String input) {
        return input.replaceAll("\\D", "");
    }

    private Map<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String,Object> params = new HashMap<>();
        params.put("game_id",game_id);
        params.put("acc_source",0);
        Map<String,Object> category = new HashMap<>();
        //1螃蟹截图  0自主上传
        params.put("screenshot_method","1");
        if (goodsInfoAndAttrValueDto.getGameName().equals("王者荣耀")) {
            params.put("camp_account", goodsInfoAndAttrValueDto.getF17());
//            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF2())) {
//                GameAttribute gameAttribute1 =
//                        gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF2()));
//                params.put("nobility_level", gameAttribute1.getFieldName().replace("V", ""));
//            }
            String response = PangXieAttrUtil.wangzhrongyaoAttr;
            JSONArray jsonArray = JSONArray.parseArray(response);
            for (Object o : jsonArray) {
                List<Integer> list = new ArrayList<>();
                boolean flag = false;
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("1")) {
                    String entries = JSONObject.parseObject(o.toString()).getString("entries");
                    JSONArray jsonArray1 = JSONArray.parseArray(entries);
                    for (Object p : jsonArray1) {
                        if (JSONObject.parseObject(p.toString()).getString("name").equals(goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName())) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"),
                                    JSONObject.parseObject(p.toString()).getInteger("id"));
                            flag = true;
                            break;
                        }
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("86")) {
                    GameAttribute gameAttribute1 =
                            gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF2()));
//                    params.put("nobility_level", gameAttribute1.getFieldName().replace("V", ""));
                    String s = removeNonDigits(gameAttribute1.getFieldName());
                    String string = JSONObject.parseObject(o.toString()).getString("entries");
                    JSONArray jsonArray1 = JSONArray.parseArray(string);
                    Integer id = 1994;
                    for (Object p : jsonArray1) {
                        String name = JSONObject.parseObject(p.toString()).getString("name");
                        if (StringUtils.equals(s, removeNonDigits(name))) {
                            id = JSONObject.parseObject(p.toString()).getInteger("id");
                            break;
                        }
                    }
                    category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), id);
                    flag = true;
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("88")) {
                    category.put("88", 1981);
                    flag = true;
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("31")) {
                    Integer string = 200;
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF16())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
                        if (gameAttribute1.getFieldName().equals("可二次实名")) {
                            string = 200;
                        } else if (gameAttribute1.getFieldName().equals("不可二次实名")) {
                            string = 201;
                        } else {
                            string = 234;
                        }
                    } else {
                        string = 200;
                    }
                    category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), string);
                    flag = true;
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("32")) {
                    category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), 203);
                    flag = true;
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("33")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF26())) {
                        List<GameAttribute> gameAttributs = getGameAttributs(goodsInfoAndAttrValueDto.getF26());
                        String string = JSONObject.parseObject(o.toString()).getString("entries");
                        JSONArray jsonArray1 = JSONArray.parseArray(string);
                        for (GameAttribute gameAttribute1 : gameAttributs) {
                            String fieldName = gameAttribute1.getFieldName();
                            if (fieldName.contains(" ")) {
                                String[] s = fieldName.split(" ");
                                if (s.length > 1) {
                                    fieldName = s[1] + s[0];
                                }
                            }
                            for (Object p : jsonArray1) {
                                String name = JSONObject.parseObject(p.toString()).getString("name");
                                if (StringUtils.equals(fieldName, name)) {
                                    list.add(JSONObject.parseObject(p.toString()).getInteger("id"));
                                    break;
                                }
                            }
                        }
                        if (CollectionUtils.isNotEmpty(list)) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), list);
                            flag = true;
                        }
                    }
                }
                if (!flag) {
                    if (StringUtils.equals(JSONObject.parseObject(o.toString()).getString("is_gaoji"), "1")) {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), new String[]{});
                    } else {
//                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), new String[]{});
                    }

                }
            }
        }
        if (goodsInfoAndAttrValueDto.getGameName().equals("和平精英")) {
            String attrs = PangXieAttrUtil.hepingjingyingAttr;
            JSONArray jsonArray = JSONArray.parseArray(attrs);
            for (Object o : jsonArray) {
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("1")) {
                    String entries = JSONObject.parseObject(o.toString()).getString("entries");
                    JSONArray jsonArray1 = JSONArray.parseArray(entries);
                    for (Object p : jsonArray1) {
                        if (JSONObject.parseObject(p.toString()).getString("name").equals(goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName())) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"),
                                    JSONObject.parseObject(p.toString()).getString("id"));
                            break;
                        }
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("7")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF10())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
                        String string = JSONObject.parseObject(o.toString()).getString("entries");
                        JSONArray jsonArray1 = JSONArray.parseArray(string);
                        for (Object p : jsonArray1) {
                            if (gameAttribute1.getFieldName().replace("包人脸", "支持人脸包赔").replace("已删实名", "可二次实名").equals(JSONObject.parseObject(p.toString()).getString("name"))) {
                                category.put(JSONObject.parseObject(o.toString()).getString("cat_id"),
                                        JSONObject.parseObject(p.toString()).getString("id"));
                            }
                        }
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("8")) {
                    category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "208");
                }
            }
//            if (sa.getjietustate==1) {
//                params.put("screenshot_method", 0);
//                StringBuffer imgs = new StringBuffer();
//                String titleImg = goodsInfoAndAttrValueDto.getTitleImg() + " ";
//                imgs.append("<img src=" + titleImg + "/>");
//            List<Map<String, Object>> urlArr = goodsInfoAndAttrValueDto.getUrlArr();
//            if (CollectionUtils.isNotEmpty(urlArr)) {
//                for (Map<String, Object> map : urlArr) {
//                    String s = String.valueOf(map.get("url"));
//                    String imgStr = s + " ";
//                    imgs.append("<img src=" + imgStr + "/>");
//                }
//            }
//                String cdata = "<p>" + imgs + "</p>";
//                params.put("cdata", cdata);
//            }
        }
        if (goodsInfoAndAttrValueDto.getGameName().equals("原神")) {
            String attrs = PangXieAttrUtil.yuanshenAttr;
            JSONArray jsonArray = JSONArray.parseArray(attrs);
            for (Object o : jsonArray) {
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("5")) {
                    if (goodsInfoAndAttrValueDto.getGroupName().contains("米哈游")) {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "134");
                    } else {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "133");
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("1")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF2())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF2()));
                        if (gameAttribute1.getFieldName().equals("未绑定邮箱")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "250");
                            category.put("8", "252");
                        } else if (gameAttribute1.getFieldName().equals("普通Q邮(随游戏出售)")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "656");
                            category.put("8", "658");
                        } else if (gameAttribute1.getFieldName().equals("字母Q邮")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "657");
                            category.put("8", "660");
                        } else if (gameAttribute1.getFieldName().equals("不送邮箱/死邮")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "2");
                            category.put("8", "251");
                        } else if (gameAttribute1.getFieldName().contains("未实名")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "1");
                            category.put("8", "249");
                        } else if (gameAttribute1.getFieldName().contains("已实名")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "1");
                            category.put("8", "248");
                        }
                    } else {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "250");
                        category.put("8", "252");
                    }
                }
//                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("4")) {
//                    if (goodsInfoAndAttrValueDto.getPrice().intValue() < 200) {
//                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "19");
//                    } else if (goodsInfoAndAttrValueDto.getPrice().intValue() >= 200 && goodsInfoAndAttrValueDto
//                    .getPrice().intValue() <= 1000) {
//                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "20");
//                    } else if (goodsInfoAndAttrValueDto.getPrice().intValue() >= 1001 && goodsInfoAndAttrValueDto
//                    .getPrice().intValue() <= 5000) {
//                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "21");
//                    } else if (goodsInfoAndAttrValueDto.getPrice().intValue() >= 5001 && goodsInfoAndAttrValueDto
//                    .getPrice().intValue() <= 10000) {
//                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "22");
//                    } else {
//                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "23");
//                    }
//                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("6")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF3())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
                        String string = JSONObject.parseObject(o.toString()).getString("entries");
                        JSONArray jsonArray1 = JSONArray.parseArray(string);
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("name").equals(gameAttribute1.getFieldName())) {
                                category.put(JSONObject.parseObject(o.toString()).getString("cat_id"),
                                        JSONObject.parseObject(p.toString()).getString("id"));
                                break;
                            }
                        }
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("28")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF20())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
                        if (gameAttribute1.getFieldName().equals("有修改人脸机会/实名是本人")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "714");
                        } else {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "715");
                        }
                    }
                }
            }
        }
        if (goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟")) {
            String attrs = PangXieAttrUtil.yingxionglijanmengAttr;
            JSONArray jsonArray = JSONArray.parseArray(attrs);
            for (Object o : jsonArray) {
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("1")) {
                    if (goodsInfoAndAttrValueDto.getGroupName().contains("电信")) {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "63");
                    } else if (goodsInfoAndAttrValueDto.getGroupName().contains("网通")) {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "83");
                    } else if (goodsInfoAndAttrValueDto.getGroupName().contains("峡谷之巅")) {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "95");
                    } else {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "99");
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("15")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF1())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
                        if (gameAttribute1.getFieldName().equals("有二次")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "320");
                        } else if (gameAttribute1.getFieldName().equals("包人脸")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "321");
                        } else {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "319");
                        }
                    }
                }
            }
            String server = "";
            if (goodsInfoAndAttrValueDto.getGroupName().equals("电信")) {
                server = "[{\"id\":7,\"pcat_id\":2,\"name\":\"艾欧尼亚\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":8,\"pcat_id\":2,\"name\":\"祖安\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"63\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":9,\"pcat_id\":2,\"name\":\"诺克萨斯\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":10,\"pcat_id\":2,\"name\":\"班德尔城\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"63\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":32,\"pcat_id\":2,\"name\":\"皮尔特沃夫\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":33,\"pcat_id\":2,\"name\":\"战争学院\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"63\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":42,\"pcat_id\":2,\"name\":\"巨神峰\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":43,\"pcat_id\":2,\"name\":\"雷瑟守备\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"63\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":44,\"pcat_id\":2,\"name\":\"裁决之地\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":45,\"pcat_id\":2,\"name\":\"黑色玫瑰\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"63\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":46,\"pcat_id\":2,\"name\":\"暗影岛\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":51,\"pcat_id\":2,\"name\":\"钢铁烈阳\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"63\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":53,\"pcat_id\":2,\"name\":\"水晶之痕\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":61,\"pcat_id\":2,\"name\":\"均衡教派\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"63\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":64,\"pcat_id\":2,\"name\":\"影流\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":65,\"pcat_id\":2,\"name\":\"守望之海\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"63\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":71,\"pcat_id\":2,\"name\":\"征服之海\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":73,\"pcat_id\":2,\"name\":\"卡拉曼达\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"63\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":75,\"pcat_id\":2,\"name\":\"皮城警备\",\"min_val\":0,\"max_val\":0,\"val\":\"63\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false}]";
            } else {
                server = "[{\"id\":77,\"pcat_id\":2,\"name\":\"比尔吉沃特\",\"min_val\":0,\"max_val\":0,\"val\":\"83\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":78,\"pcat_id\":2,\"name\":\"德玛西亚\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"83\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":84,\"pcat_id\":2,\"name\":\"弗雷尔卓德\",\"min_val\":0,\"max_val\":0,\"val\":\"83\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":85,\"pcat_id\":2,\"name\":\"无畏先锋\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"83\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":91,\"pcat_id\":2,\"name\":\"恕瑞玛\",\"min_val\":0,\"max_val\":0,\"val\":\"83\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false},{\"id\":92,\"pcat_id\":2,\"name\":\"扭曲丛林\"," +
                        "\"min_val\":0,\"max_val\":0,\"val\":\"83\",\"sort\":50,\"status\":1,\"haveChild\":false}," +
                        "{\"id\":93,\"pcat_id\":2,\"name\":\"巨龙之巢\",\"min_val\":0,\"max_val\":0,\"val\":\"83\"," +
                        "\"sort\":50,\"status\":1,\"haveChild\":false}]";
            }
            JSONArray jsonArray1 = JSONArray.parseArray(server);
            for (Object o : jsonArray1) {
                if (JSONObject.parseObject(o.toString()).getString("name").equals(goodsInfoAndAttrValueDto.getServerName())) {
                    category.put("2", JSONObject.parseObject(o.toString()).getInteger("id"));
                    break;
                }
            }
        }
        if (goodsInfoAndAttrValueDto.getGameName().equals("穿越火线")) {
            String attrs = PangXieAttrUtil.chuanyuehuoxianAttr;
            JSONArray jsonArray = JSONArray.parseArray(attrs);
            for (Object o : jsonArray) {
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("1")) {
                    String string = JSONObject.parseObject(o.toString()).getString("entries");
                    JSONArray jsonArray1 = JSONArray.parseArray(string);
                    for (Object p : jsonArray1) {
                        if (goodsInfoAndAttrValueDto.getGroupName().contains(JSONObject.parseObject(p.toString()).getString("name"))) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"),
                                    JSONObject.parseObject(o.toString()).getString("id"));
                            break;
                        }
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("11")) {
                    category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "225");
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("10")) {
                    category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "219");
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("12")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF3())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
                        if (gameAttribute1.getFieldName().equals("有修改机会且实名是本人")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "229");
                        } else if (gameAttribute1.getFieldName().equals("无修改机会且实名是本人")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "232");
                        } else {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "228");
                        }
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("20")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF20())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
                        if (gameAttribute1.getFieldName().contains("雷神")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "676");
                        } else if (gameAttribute1.getFieldName().contains("毁灭")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "677");
                        } else if (gameAttribute1.getFieldName().contains("火麒麟")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "678");
                        } else {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "681");
                        }
                    } else {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "681");
                    }
                }
            }
            String server = "";
            if (goodsInfoAndAttrValueDto.getGroupName().equals("东部战区")) {
                server = PangXieAttrUtil.chuanyuehuoxianDongServer;
            } else if (goodsInfoAndAttrValueDto.getGroupName().equals("南部战区")) {
                server = PangXieAttrUtil.chuanyuehuoxianNanServer;
            } else if (goodsInfoAndAttrValueDto.getGroupName().equals("西部战区")) {
                server = PangXieAttrUtil.chuanyuehuoxianXiServer;
            } else if (goodsInfoAndAttrValueDto.getGroupName().equals("北部战区")) {
                server = PangXieAttrUtil.chuanyuehuoxianBeiServer;
            }
            JSONArray jsonArray1 = JSONArray.parseArray(server);
            for (Object o : jsonArray1) {
                if (JSONObject.parseObject(o.toString()).getString("name").equals(goodsInfoAndAttrValueDto.getServerName())) {
                    category.put("2", JSONObject.parseObject(o.toString()).getInteger("id"));
                    break;
                }
            }
        }
        if (goodsInfoAndAttrValueDto.getGameName().equals("枪战王者")) {
            params.put("screenshot_method", "0");
            StringBuffer imgs = new StringBuffer();
            String titleImg = goodsInfoAndAttrValueDto.getTitleImg() + " ";
            imgs.append("<img src=" + titleImg + "/>");
            List<Map<String, Object>> urlArr = goodsInfoAndAttrValueDto.getUrlArr();
            if (CollectionUtils.isNotEmpty(urlArr)) {
                for (Map<String, Object> map : urlArr) {
                    String s = String.valueOf(map.get("url"));
                    String imgStr = s + " ";
                    imgs.append("<img src=" + imgStr + "/>");
                }
            }
            String cdata = "<p>" + imgs + "</p>";
            params.put("cdata", cdata);
            String attrs = PangXieAttrUtil.qiangzhanwangzheAttr;
            JSONArray jsonArray = JSONArray.parseArray(attrs);
            for (Object o : jsonArray) {
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("1")) {
                    String string = JSONObject.parseObject(o.toString()).getString("entries");
                    JSONArray jsonArray1 = JSONArray.parseArray(string);
                    for (Object p : jsonArray1) {
                        if (JSONObject.parseObject(p.toString()).getString("name").equals(goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName())) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"),
                                    JSONObject.parseObject(p.toString()).getString("id"));
                            break;
                        }
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("6")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF10())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
                        if (gameAttribute1.getFieldName().equals("有修改人脸机会/实名是本人")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "80");
                        } else if (gameAttribute1.getFieldName().equals("无修改人脸机会/实名是本人")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "178");
                        } else {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "81");
                        }
                    } else {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "178");
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("12")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF2())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF2()));
                        String entries = JSONObject.parseObject(o.toString()).getString("entries");
                        JSONArray jsonArray1 = JSONArray.parseArray(entries);
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("name").replace("VIP", "").replace("级"
                                    , "").equals(gameAttribute1.getFieldName().replace("V", "").replace("无", "1"))) {
                                category.put(JSONObject.parseObject(o.toString()).getString("cat_id"),
                                        JSONObject.parseObject(p.toString()).getString("id"));
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (goodsInfoAndAttrValueDto.getGameName().equals("火影忍者")) {
            String options = PangXieAttrUtil.huoyingrenzheAttr;
            JSONArray jsonArray = JSONArray.parseArray(options);
            for (Object o : jsonArray) {
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("1")) {
                    String string = JSONObject.parseObject(o.toString()).getString("entries");
                    JSONArray jsonArray1 = JSONArray.parseArray(string);
                    for (Object p : jsonArray1) {
                        if (JSONObject.parseObject(p.toString()).getString("name").equals(goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName())) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"),
                                    JSONObject.parseObject(o.toString()).getString("id"));
                            break;
                        }
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("8")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF7())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF7()));
                        if (gameAttribute1.getFieldName().equals("可改二次")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "131");
                        } else if (gameAttribute1.getFieldName().equals("不可二次") || gameAttribute1.getFieldName().equals("已删实名")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "132");
                        } else if (gameAttribute1.getFieldName().equals("人脸包赔")) {
                            category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "149");
                        }
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("7")) {
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF3())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
                        String entries = JSONObject.parseObject(o.toString()).getString("entries");
                        JSONArray jsonArray1 = JSONArray.parseArray(entries);
                        for (Object p : jsonArray1) {
                            if (gameAttribute1.getFieldName().contains(JSONObject.parseObject(p.toString()).getString("name"))) {
                                category.put(JSONObject.parseObject(o.toString()).getString("cat_id"),
                                        JSONObject.parseObject(p.toString()).getString("cat_id"));
                                break;
                            }
                        }
                    } else {
                        category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), "186");
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("cat_id").equals("9")) {
                    String id = "152";
                    if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF10())) {
                        GameAttribute gameAttribute1 =
                                gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
                        String entries = JSONObject.parseObject(o.toString()).getString("entries");
                        JSONArray jsonArray1 = JSONArray.parseArray(entries);
                        for (Object p : jsonArray1) {
                            String name = JSONObject.parseObject(p.toString()).getString("name");
                            String fieldName = gameAttribute1.getFieldName();
                            if (StringUtils.equals(name, fieldName)) {
                                id = JSONObject.parseObject(p.toString()).getString("id");
                                break;
                            }
                        }

                    }
                    category.put(JSONObject.parseObject(o.toString()).getString("cat_id"), id);
                }
            }
            params.put("screenshot_method", "0");
            StringBuffer imgs = new StringBuffer();
            String titleImg = goodsInfoAndAttrValueDto.getTitleImg() + " ";
            imgs.append("<img src=" + titleImg + "/>");
            List<Map<String, Object>> urlArr = goodsInfoAndAttrValueDto.getUrlArr();
            if (CollectionUtils.isNotEmpty(urlArr)) {
                for (Map<String, Object> map : urlArr) {
                    String s = String.valueOf(map.get("url"));
                    String imgStr = s + " ";
                    imgs.append("<img src=" + imgStr + "/>");
                }
            }
            String cdata = "<p>" + imgs + "</p>";
            params.put("cdata", cdata);
            Random random = new Random();
            int randomNumber = random.nextInt(2150) + 1;
            params.put("server", randomNumber);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("永劫无间")){
            params.put("acc_source","1");
            category.put("1",1);
            if(goodsInfoAndAttrValueDto.getServerName().equals("网易手机帐号")){
                category.put("6",128);
            }else {
                category.put("6",129);
            }
            category.put("59",1311);
            category.put("60",1316);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("无畏契约")){
            params.put("acc_source",1);
            category.put("2",4);
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF1())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
                if(gameAttribute1.getFieldName().equals("可二次实名")){
                    category.put("3",7);
                }else {
                    category.put("3",6);
                }
            }
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF27())) {
                params.put("zhang_wa_account", goodsInfoAndAttrValueDto.getF27().trim());
            }
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟(手游)")){
            params.put("acc_source",0);
            params.put("screenshot_method",0);
            StringBuffer imgs = new StringBuffer();
            GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
            goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
            goodsInfoImg.setType(Constants.STR_1);
            List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
            for (GoodsInfoImg goodsInfoImg1 : infoImgs) {
                String imgStr = goodsInfoImg1.getImgUrl() + " ";
                imgs.append("<img src=" + imgStr + "/>");
            }
            String titleImg = goodsInfoAndAttrValueDto.getTitleImg() + " ";
            imgs.append("<img src=" + titleImg + "/>");
            String cdata = "<p>"+imgs+"</p>";
            params.put("cdata",cdata);
            category.put("1","1");
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("安卓QQ")) {
                category.put("2", "2");
            }else if(regional.equals("苹果QQ")){
                category.put("2", "3");
            }else if(regional.equals("安卓微信")){
                category.put("2", "4");
            }else {
                category.put("2", "5");
            }
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF4())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF4()));
                if(gameAttribute1.getFieldName().equals("可二次实名")){
                    category.put("3", "7");
                }else if(gameAttribute1.getFieldName().equals("包人脸")){
                    category.put("3", "9");
                }else {
                    category.put("3", "8");
                }
            }
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("永劫无间手游")){
            if(goodsInfoAndAttrValueDto.getCarrierName().equals("网易手机")) {
                category.put("2", "4");
            }else {
                category.put("2", "5");
            }
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF36())) {
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF36()));
                if(gameAttribute1.getFieldName().equals("可注销")) {
                    category.put("28", "182");
                }else {
                    category.put("28", "183");
                }
            }
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF23())) {
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF23()));
                if(gameAttribute1.getFieldName().equals("未绑定")) {
                    category.put("27", "177");
                }else {
                    category.put("27", "178");
                }
            }
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("金铲铲之战")){
            params.put("screenshot_method",0);

            StringBuffer imgs = new StringBuffer();
            GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
            goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
            goodsInfoImg.setType(Constants.STR_1);
            List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
            for (GoodsInfoImg goodsInfoImg1 : infoImgs) {
                String imgStr = goodsInfoImg1.getImgUrl() + " ";
                imgs.append("<img src=" + imgStr + "/>");
            }
            String titleImg = goodsInfoAndAttrValueDto.getTitleImg() + " ";
            imgs.append("<img src=" + titleImg + "/>");
            String cdata = "<p>"+imgs+"</p>";
            params.put("cdata",cdata);
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("安卓QQ")) {
                category.put("1", "6");
            }else if(regional.equals("安卓微信")) {
                category.put("1", "63");
            }else if(regional.equals("苹果QQ")) {
                category.put("1", "1");
            }else {
                category.put("1", "2");
            }
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF1())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
                if(gameAttribute1.getFieldName().equals("可二次实名")){
                    category.put("7", "153");
                }else {
                    category.put("7", "152");
                }
            }else {
                category.put("7", "152");
            }
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF17())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF17()));
                String string = "[{\"id\":351,\"pcat_id\":11,\"name\":\"无等级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":1,\"status\":1,\"haveChild\":false},{\"id\":341,\"pcat_id\":11,\"name\":\"VIP1级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":2,\"status\":1,\"haveChild\":false},{\"id\":342,\"pcat_id\":11,\"name\":\"VIP2级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":3,\"status\":1,\"haveChild\":false},{\"id\":343,\"pcat_id\":11,\"name\":\"VIP3级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":4,\"status\":1,\"haveChild\":false},{\"id\":344,\"pcat_id\":11,\"name\":\"VIP4级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":5,\"status\":1,\"haveChild\":false},{\"id\":345,\"pcat_id\":11,\"name\":\"VIP5级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":6,\"status\":1,\"haveChild\":false},{\"id\":346,\"pcat_id\":11,\"name\":\"VIP6级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":7,\"status\":1,\"haveChild\":false},{\"id\":347,\"pcat_id\":11,\"name\":\"VIP7级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":8,\"status\":1,\"haveChild\":false},{\"id\":348,\"pcat_id\":11,\"name\":\"VIP8级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":9,\"status\":1,\"haveChild\":false},{\"id\":349,\"pcat_id\":11,\"name\":\"VIP9级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":10,\"status\":1,\"haveChild\":false},{\"id\":350,\"pcat_id\":11,\"name\":\"VIP10级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":11,\"status\":1,\"haveChild\":false},{\"id\":356,\"pcat_id\":11,\"name\":\"VIP11级\",\"min_val\":0,\"max_val\":0,\"val\":\"\",\"sort\":12,\"status\":1,\"haveChild\":false}]\n";
                JSONArray jsonArray = JSONArray.parseArray(string);
                for(Object o : jsonArray){
                    if(JSONObject.parseObject(o.toString()).getString("name").replace("级","").equals(gameAttribute1.getFieldName())){
                        category.put("11", JSONObject.parseObject(o.toString()).getString("id"));
                        break;
                    }
                }
            }
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("暗区突围")){
            params.put("screenshot_method",0);
            StringBuffer imgs = new StringBuffer();
            GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
            goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
            goodsInfoImg.setType(Constants.STR_1);
            List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
            for (GoodsInfoImg goodsInfoImg1 : infoImgs) {
                String imgStr = goodsInfoImg1.getImgUrl() + " ";
                imgs.append("<img src=" + imgStr + "/>");
            }
            String titleImg = goodsInfoAndAttrValueDto.getTitleImg() + " ";
            imgs.append("<img src=" + titleImg + "/>");
            String cdata = "<p>"+imgs+"</p>";
            params.put("cdata",cdata);
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("安卓QQ")) {
                category.put("1", "1");
            }else if(regional.equals("安卓微信")) {
                category.put("1", "2");
            }else if(regional.equals("苹果QQ")) {
                category.put("1", "3");
            }else {
                category.put("1", "4");
            }
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF3())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
                if(gameAttribute1.getFieldName().equals("可二次实名")){
                    category.put("2", "6");
                }else {
                    category.put("2", "5");
                }
            }else {
                category.put("2", "5");
            }
            category.put("3", "8");
        }
        params.put("description",goodsInfoAndAttrValueDto.getDes().length()>250?goodsInfoAndAttrValueDto.getDes().substring(0,250):goodsInfoAndAttrValueDto.getDes());
        params.put("game_account",goodsInfoAndAttrValueDto.getAccountNumber());
        params.put("game_pwd",goodsInfoAndAttrValueDto.getAccountPassword());
        params.put("game_pwd_confirm",goodsInfoAndAttrValueDto.getAccountPassword());
        params.put("is_premium","1");
        params.put("name",goodsInfoAndAttrValueDto.getTitle());
        params.put("is_sign","1");
//        params.put("serve",0);
        params.put("phone",salePartner.getSaleKey());
        params.put("wx",salePartner.getSaleKey());
        params.put("qq",salePartner.getSaleKey().substring(0,9));
        params.put("price",goodsInfoAndAttrValueDto.getPrice().setScale(0, BigDecimal.ROUND_FLOOR).toPlainString());
        params.put("category",JSONObject.toJSONString(category));
        return params;
    }
    /**
     * 获取随机数
     *
     * @return
     */
    public static String getRanString() {
        Random random = new Random();
        //把随机生成的数字转成字符串
        String str = String.valueOf(random.nextInt(9));
        for (int i = 0; i < 9; i++) {
            str += random.nextInt(9);
        }
        if (str.startsWith("0")) {
            str = str.replaceFirst("0", "1");
        }
        return str;
    }

    String getToken(SalePartner salePartner) {
        String url = "https://api.pxb7.com/api/login";
        Map<String, String> params1 = new HashMap<>();
        params1.put("phone", salePartner.getSaleKey());
        params1.put("pwd", salePartner.getOther());
        long timestamp = System.currentTimeMillis() / 1000;
        String appSecret = "198f788b9ee343209e0121bf72e8c562";
        String ranString = getRanString();
        StringBuilder sb = new StringBuilder();
        sb.append("APPSECRET=");
        sb.append(appSecret);
        sb.append("&{\"PHONE\":");
        sb.append("\"" + salePartner.getSaleKey() + "\"");
        sb.append(",");
        sb.append("\"PWD\":");
        sb.append("\"" + salePartner.getOther() + "\"");
        sb.append("}");
        sb.append("&TIMESTAMP=");
        sb.append(timestamp);
        sb.append("&RANDOMSTR=");
        sb.append(ranString);

        System.out.println(sb.toString());
        String sign = DigestUtils.md5Hex(sb.toString().toUpperCase());
        System.out.println(sign);


        String response = HttpRequest.post(url)
                .header("Accept", "application/json, text/plain, */*")
                .header("Accept-Language", "zh-CN,zh;q=0.9")
                .header("ApiToken", salePartner.getThreeOther())
                .header("Connection", "keep-alive")
                .header("Content-Type", "application/json;charset=UTF-8")
                .header("LoginStatus", "false")
                .header("Origin", "https://www.pxb7.com")
                .header("Sec-Fetch-Dest", "empty")
                .header("Sec-Fetch-Mode", "cors")
                .header("Sec-Fetch-Site", "same-site")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like " +
                        "Gecko) Chrome / 122.0 .0 .0 Safari / 537.36 ")
                .header("randomStr", ranString)
                .header("sec-ch-ua", "\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"")
                .header("sec-ch-ua-mobile", "?0")
                .header("sec-ch-ua-platform", "\"Windows\"")
                .header("sign", sign)
                .header("timestamp", String.valueOf(timestamp))
                .header("token", salePartner.getTwoOther())
                .body(JSONObject.toJSONString(params1)).execute().body();

        log.info(response);
        JSONObject jsonObject = JSONObject.parseObject(response);
        if ("200".equals(jsonObject.getString("code"))) {
            String data = jsonObject.getString("data");
            String aes = aes(data);
            return aes;
        }
        return null;
    }

    public static String aes(String data){
        try {
            String key = "C01F8012D3F6386C";
            String iv = "245C3EA487E944FD";
            String encryptedText = data;
            SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES");
            IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes());

            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);

            byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedText));
            String decryptedText = new String(decryptedBytes, "UTF-8");
            JSONObject jsonObject = JSONObject.parseObject(decryptedText);
            return jsonObject.getString("token");
        }catch (Exception e){
            throw new GlobalException("AES加密失败！！！");
        }
    }


    String getAttrs(Integer game_id, SalePartner salePartner) {
        String token = getToken(salePartner);
        log.info(token);
        String url = "https://api.pxb7.com/api/product/category?game_id="+game_id+"&type=sale";
        String body = HttpRequest.get(url)
                .header("Host","api.pxb7.com")
                .header("Content-Type","application/json;charset=UTF-8")
                .header("Authorization",token)
                .header("Accept","application/json, text/plain, */*")
                .header("Origin","https://www.pxb7.com")
                .header("Loginstatus","true")
                .execute().body();
//        log.info(body);
        return body;
    }


    private List<GameAttribute> getGameAttributs(String ids) {
        if (StringUtils.isEmpty(ids)) {
            return new ArrayList<>();
        }
        return gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(ids.split(","),
                Long.class));
    }

    private String reIds(String allIds, String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            if (StringUtils.isNotEmpty(allIds)) {
                allIds = allIds + "," + ids;
            } else {
                allIds = ids;
            }
        }
        return allIds;
    }

}

